import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import moment from 'moment';
import countries from './country';
import city from './city';

export const columns: BasicColumn[] = [
  {
    title: '名字',
    dataIndex: 'name',
  },
  {
    title: '姓氏',
    dataIndex: 'lastName',
  },
  {
    title: '电子邮件',
    dataIndex: 'email',
  },
  {
    title: '电话号码',
    dataIndex: 'phone',
  },
  {
    title: '公司名称',
    dataIndex: 'companyName',
  },
  {
    title: '地址',
    dataIndex: 'address',
  },
  {
    title: '国家',
    dataIndex: 'country',
    customRender: ({ record }) => {
      const index = countries.findIndex((item) => item.value === record.country);
      return countries[index].label;
    },
  },
  {
    title: '省/州',
    dataIndex: 'state',
    customRender: ({ record }) => {
      const index = city.findIndex((item) => item.value === record.state);
      return index === -1 ? '' : city[index].label;
    },
  },
  {
    title: '城市',
    dataIndex: 'city',
    customRender: ({ record }) => {
      let cityName = '';
      city.forEach((item) => {
        if (item.children) {
          item.children.forEach((item1) => {
            if (item1.value === record.city) cityName = item1.label;
          });
        } else {
          cityName = '';
        }
      });
      return cityName;
    },
  },
  {
    title: '邮政编码',
    dataIndex: 'postalCode',
  },
  {
    title: '客户等级',
    dataIndex: 'cusLevel',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '岗位名称',
    component: 'Input',
    colProps: { span: 8 },
    componentProps: {
      placeholder: '请输入岗位名称',
    },
  },
  {
    field: 'code',
    label: '岗位标识',
    component: 'Input',
    colProps: { span: 8 },
    componentProps: {
      placeholder: '请输入岗位标识',
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '名字',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入名字',
    },
  },
  {
    field: 'lastName',
    label: '姓氏',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入姓氏',
    },
  },
  {
    field: 'email',
    label: '电子邮箱',
    required: true,
    component: 'Input',
    componentProps: {
      placeholder: '请输入电子邮箱',
    },
  },
  {
    field: 'phone',
    label: '电话号码',
    component: 'InputNumber',
    componentProps: {
      placeholder: '请输入电话号码',
    },
  },
  {
    field: 'companyName',
    label: '公司名称',
    component: 'Input',
    componentProps: {
      placeholder: '请输入公司名称',
    },
  },
  {
    field: 'address',
    label: '地址',
    component: 'Input',
    componentProps: {
      placeholder: '请输入地址',
    },
  },
  {
    label: '国家',
    field: 'country',
    component: 'Select',
    componentProps: {
      options: countries,
      showSearch: true,
      filterOption: (input, option) => {
        return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
      },
    },
  },
  {
    label: '省市',
    field: 'city',
    slot: 'customSlot',
    component: 'Cascader',
  },
  {
    field: 'postalCode',
    label: '邮政编码',
    component: 'Input',
    componentProps: {
      placeholder: '请输入邮政编码',
      max: 3,
      min: 0,
    },
  },
  {
    field: 'cusLevel',
    label: '客户等级',
    component: 'InputNumber',
    componentProps: {
      placeholder: '请输入客户等级',
      max: 3,
      min: 0,
    },
  },
];
